package com.intellij.ide.license.impl;

import com.intellij.licensecommon.data.LicenseData;
import com.intellij.licensecommon.data.h;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class SubscriptionLicenseValidator extends GeneralLicenseValidator {
    private final Date b;
    public static final long DEFAULT_LICENSE_CHECK_PERIOD = TimeUnit.MILLISECONDS.convert(1L, TimeUnit.DAYS);

    public SubscriptionLicenseValidator(int licenseType, Date paramDate) {
        super(licenseType);
        this.b = paramDate;
    }

    @Override
    protected void checkUpgrade(LicenseData licenseData) throws LicenseException {
        if ((licenseData instanceof h)) {
            checkMaintenancePeriod(((h) licenseData).getUpgradeDueDate());
        } else {
            checkDefaultMaintenanceDueDate(licenseData);
        }
    }

    private void checkDefaultMaintenanceDueDate(LicenseData licenseData) throws LicenseException {
        if (licenseData == null) {
            throw new IllegalArgumentException(String.format("Argument %s for  parameter of %s.%s must not be null", new Object[]{"0", "com/intellij/ide/license/impl/SubscriptionLicenseValidator", "checkDefaultMaintenanceDueDate"}));
        }
        Date generationDate = licenseData.getGenerationDate();
        Date localDate2 = new Date(generationDate.getTime() + DEFAULT_LICENSE_CHECK_PERIOD);

        checkMaintenancePeriod(localDate2);
    }

    private void checkMaintenancePeriod(Date paramDate) throws LicenseException {
        if (paramDate == null) {
            throw new IllegalArgumentException(String.format("Argument %s for  parameter of %s.%s must not be null", new Object[]{"0", "com/intellij/ide/license/impl/SubscriptionLicenseValidator", "checkMaintenancePeriod"}));
        }
        if (this.b.getTime() > paramDate.getTime()) {
            throw new VersionNotMatchLicenseException();
        }
    }
}
